<html>
<head><meta charset="utf-8"><title>Getting a String from a struct with Option&lt;String&gt; field · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html">Getting a String from a struct with Option&lt;String&gt; field</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212977661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977661">(Oct 11 2020 at 19:13)</a>:</h4>
<p>Suppose I have <code>struct S { field: Option&lt;String&gt; }</code>. I have a variable <code>s</code> of type <code>S</code>. Is there a simpler way to get the <code>String</code> out of the field without doing <code>s.field.as_ref().expect("...").clone()</code>?</p>



<a name="212977708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977708">(Oct 11 2020 at 19:14)</a>:</h4>
<p><code>s.field.cloned().expect("...")</code></p>



<a name="212977714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977714">(Oct 11 2020 at 19:14)</a>:</h4>
<p>Ah, I didn't realize <code>Option</code> had <code>cloned</code>!</p>



<a name="212977715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977715">(Oct 11 2020 at 19:14)</a>:</h4>
<p>Handy.</p>



<a name="212977730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977730">(Oct 11 2020 at 19:15)</a>:</h4>
<p>Oh, wait, that wants an <code>Option&lt;&amp;T&gt;</code>...</p>



<a name="212977733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977733">(Oct 11 2020 at 19:15)</a>:</h4>
<p>I have an <code>Option&lt;String&gt;</code>.</p>



<a name="212977736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977736">(Oct 11 2020 at 19:15)</a>:</h4>
<p>oh I see</p>



<a name="212977739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977739">(Oct 11 2020 at 19:15)</a>:</h4>
<p>does <code>s.field.clone()</code> work then?</p>



<a name="212977787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977787">(Oct 11 2020 at 19:16)</a>:</h4>
<p>Ah. Yes, it does, and since <code>None</code> is a weird error case I don't really care if a clone happens on that path.</p>



<a name="212977801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977801">(Oct 11 2020 at 19:17)</a>:</h4>
<p>Do you know, offhand, if cloning the <code>Option&lt;String&gt;</code> and then using <code>.expect("...")</code> to get the <code>String</code> out will avoid copying the string more than once?</p>



<a name="212977867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977867">(Oct 11 2020 at 19:18)</a>:</h4>
<p>I don't know what you mean by copying - you mean like the assembly it emits? At the language level there's only one copy</p>



<a name="212977935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977935">(Oct 11 2020 at 19:20)</a>:</h4>
<p>I'm wondering how many <code>memcpy</code>s occur when I write:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">s</span><span class="p">.</span><span class="n">field</span><span class="p">.</span><span class="n">clone</span><span class="p">().</span><span class="n">expect</span><span class="p">(</span><span class="s">"..."</span><span class="p">);</span><span class="w"></span>
<span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="n">OtherStruct</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">foo</span>: <span class="nc">vec</span><span class="o">!</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
</code></pre></div>



<a name="212977953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977953">(Oct 11 2020 at 19:21)</a>:</h4>
<p>(Ideally I'd like to avoid cloning the string at all, since the struct containing that field is going away immediately, so the new String should really be able to own the data.)</p>



<a name="212977961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212977961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212977961">(Oct 11 2020 at 19:21)</a>:</h4>
<p>why do you need a clone then? I think you can move parts of a struct as long as you don't need the full struct for anything</p>



<a name="212978001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978001">(Oct 11 2020 at 19:22)</a>:</h4>
<p>I would love to do that, except that <code>Option&lt;String&gt;</code> doesn't seem happy with me doing that.</p>



<a name="212978010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978010">(Oct 11 2020 at 19:22)</a>:</h4>
<p><code>s.field.expect("...")</code> gives <code>error[E0507]: cannot move out of a shared reference</code>.</p>



<a name="212978014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978014">(Oct 11 2020 at 19:22)</a>:</h4>
<p><code>move occurs because value has type `std::option::Option&lt;std::string::String&gt;`, which does not implement the `Copy` trait</code></p>



<a name="212978020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978020">(Oct 11 2020 at 19:23)</a>:</h4>
<p>that sounds like <code>s</code> itself is a borrow</p>



<a name="212978031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978031">(Oct 11 2020 at 19:23)</a>:</h4>
<p>...oh, hang on a moment, you're right.</p>



<a name="212978073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978073">(Oct 11 2020 at 19:24)</a>:</h4>
<p>Sigh, that'll teach me to oversimplify.</p>



<a name="212978075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978075">(Oct 11 2020 at 19:24)</a>:</h4>
<p>It's not that <code>s</code> was a borrow.</p>



<a name="212978076"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978076" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978076">(Oct 11 2020 at 19:24)</a>:</h4>
<p>It's that I was getting this out of a <code>Vec</code>.</p>



<a name="212978082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978082">(Oct 11 2020 at 19:24)</a>:</h4>
<p>The concrete code, using rusoto:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">instance_id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">reservation</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">instances</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">unwrap_or_else</span><span class="p">(</span><span class="o">||</span><span class="w"> </span><span class="n">vec</span><span class="o">!</span><span class="p">[])</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">pop</span><span class="p">()</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">expect</span><span class="p">(</span><span class="s">"RunInstances successful but no instance ID"</span><span class="p">)</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">instance_id</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">expect</span><span class="p">(</span><span class="s">"Instance had no ID"</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="212978092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978092">(Oct 11 2020 at 19:25)</a>:</h4>
<p>hmm that sounds like it should work</p>



<a name="212978093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978093">(Oct 11 2020 at 19:25)</a>:</h4>
<p>It does. :)</p>



<a name="212978098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978098">(Oct 11 2020 at 19:25)</a>:</h4>
<p>(I switched from <code>.get(0)</code> to <code>.pop()</code> when you mentioned the possibility that there was a borrow in there. :) )</p>



<a name="212978134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978134">(Oct 11 2020 at 19:26)</a>:</h4>
<p><code>Reservation</code> contains <code>instances: Option&lt;Vec&lt;Instance&gt;&gt;</code>, and <code>Instance</code> contains <code>instance_id: Option&lt;String&gt;</code>.</p>



<a name="212978142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978142">(Oct 11 2020 at 19:26)</a>:</h4>
<p>Because there need to be <em>more</em> ways for things to be optional...</p>



<a name="212978146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978146">(Oct 11 2020 at 19:26)</a>:</h4>
<p>you might want an <code>assert_eq!(instances.len(), 1)</code> in there somewhere</p>



<a name="212978160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978160">(Oct 11 2020 at 19:27)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> Considering that <em>all</em> the error handling there is "AWS is violating its own documentation" (which granted does happen occasionally), I think I can ignore the possibility that I asked for 1 instance and got more than one. ;)</p>



<a name="212978167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978167">(Oct 11 2020 at 19:27)</a>:</h4>
<p>Asking for 1 and getting less than one seems more plausible.</p>



<a name="212978168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978168">(Oct 11 2020 at 19:27)</a>:</h4>
<p>sounds good to me</p>



<a name="212978170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978170">(Oct 11 2020 at 19:27)</a>:</h4>
<p>Thanks for the debugging assistance. :)</p>



<a name="212978171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978171">(Oct 11 2020 at 19:27)</a>:</h4>
<p>This is much cleaner.</p>



<a name="212978180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212978180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212978180">(Oct 11 2020 at 19:27)</a>:</h4>
<p>no problem :)</p>



<a name="212979263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212979263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212979263">(Oct 11 2020 at 19:58)</a>:</h4>
<p>(On <del>nightly</del> beta you can also <code>.try_into()</code> a <code>[T; 1]</code>, if you prefer that to <code>pop</code>.)</p>



<a name="212979929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20a%20String%20from%20a%20struct%20with%20Option%3CString%3E%20field/near/212979929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20a.20String.20from.20a.20struct.20with.20Option.3CString.3E.20field.html#212979929">(Oct 11 2020 at 20:16)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> I'm currently using stable, but I look forward to that.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>